package com.jiwei.community.controller;

import com.jiwei.community.entity.Section;
import com.jiwei.community.enums.AppHttpCodeEnum;
import com.jiwei.community.service.SectionService;
import com.jiwei.community.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 季伟
 * @date 2024/3/29
 */
@RestController
@RequestMapping("/section")
public class SectionController {
    @Autowired
    SectionService sectionService;
    @PostMapping("")
    public ResponseResult addSection(@RequestBody Section section){
        if (section.getCommunityId() == null)return ResponseResult.errorResult(AppHttpCodeEnum.BAD_REQUEST,"communityId不能为空");
        sectionService.save(section);
        return ResponseResult.okResult(section,"添加成功");
    }
    @GetMapping("/byCommunityId/{communityId}")
    public ResponseResult getSectionsByCommunityId(@PathVariable Long communityId){
        return sectionService.getSectionsByCommunityId(communityId);
    }
}
